//
// Created by Administrator on 12/5/2022.
//

#ifndef __BSP_H
#define __BSP_H

#include "stm32g0xx.h"
#include "main.h"
#include "frm_struct_def.h"

#define ADC_VAL_LEN 384
extern uint32_t ADC_VAL[ADC_VAL_LEN];
#define ADC_CH_CURR ADC_CHANNEL_0
#define ADC_CH_VBUS ADC_CHANNEL_1
#define ADC_CH_EXT ADC_CHANNEL_6
#define STEPPED_SPEED_DEFAULT 1000

#define RX_BUFF_MAX 128
extern uint8_t RX_BUFF[RX_BUFF_MAX];

void configChannel(uint32_t ch);

#define PKG_HEAD "PKGHEAD"
#define PKG_DATA_SIZE 48

typedef struct digitubeFrm // 48 bytes
{
    uint8_t channel;
    long currValue;
}digitubeFrm;

typedef struct
{
    /* 步进电机相关变量 */
    uint32_t stepDir;
    uint32_t stepSpeed;
    int stepCntCurr;
    int stepCntDst;
    int stickerInput;
} device;
extern device g_step1;
extern device g_step2;
void writeROM(const uint8_t* data, uint32_t length);
void readROM(uint8_t* data, uint32_t len);
uint8_t validPkg(const pkg* s);
void BspInit(void);
void BspUpdateAdcInput(void);
void BspConfigSpeed(uint32_t speedX, uint32_t speedY);

#endif //__BSP_H
